


	/*
	*	@ary Image 리스트
	*	@container Image를 담을 컨테이너.
	*	@fps 초당 프레임 수.
	*/
	var MovieClip = function( ary, container, fps )
	{

		var totalFrame, delay, currentFrame, isPlay, dicScript, i, len, ctx;
		
		totalFrame = ary.length;
		currentFrame = 1;
		delay = 1000/fps;
		isPlay = false;
		dicScript = {};
		
		ctx = container.getContext("2d");
		
		/*
		i=0;
		len=ary.length;
		while( i<len )
		{
			container.appendChild( ary[ i ] );
			ary[ i ].style.position = "absolute";
			ary[ i ].style.visibility = "hidden";
			++i;	
		}
		
		ary[ 0 ].style.visible = "visible";
		*/
		
		this.getCurrentFrame = function()
		{
			return currentFrame;
		}
		
		this.getTotalFrame = function()
		{
			return totalFrame;	
		}
		
		this.prevFrame = function()
		{
			isPlay = false;	
			moveFrame( currentFrame-1 );
		}
		
		this.nextFrame = function()
		{
			isPlay = false;	
			moveFrame( currentFrame+1 );
		}
		
		this.gotoAndStop = function( frameNum )
		{
			isPlay = false;	
			moveFrame( frameNum );
		}
		
		this.gotoAndPlay = function( frameNum )
		{
			moveFrame( frameNum-1 );
			
			if( isPlay == false )
			{
				isPlay = true;
				playLoop();
			}
		}
		
		this.play = function()
		{
			if( isPlay == false )
			{
				isPlay = true;
				playLoop();
			}
		}
		
		this.stop = function()
		{
			isPlay = false;	
		}
		
		this.addFrameScript = function( frameNum, script )
		{
			dicScript[ frameNum ] = script;
		}
		
		this.setSize = function( width, height )
		{
			container.width = width;
			container.height = height;	
		}
		
		
		
		var playLoop = function()
		{	
			if( isPlay == false ) return;
			if( currentFrame == totalFrame ) moveFrame( 1 );
			else moveFrame( currentFrame+1 );
			
			setTimeout( playLoop, delay );
		}
		
		var moveFrame = function( frameNum )
		{
			
			//ary[ currentFrame-1 ].style.visibility = "hidden";
			//container.removeChild( ary[ currentFrame-1 ] );
			
			currentFrame = frameNum;
			if( currentFrame > totalFrame ) currentFrame = totalFrame;
			else if( currentFrame < 1 ) currentFrame = 1;
			
			//ary[ currentFrame-1 ].style.visibility = "visible";
			//container.appendChild( ary[ currentFrame-1 ] );
			
			var img = ary[ currentFrame-1 ];
			ctx.drawImage(img,0,0);
			
			if( typeof dicScript[ frameNum ] !== "undefined" )
			{
				dicScript[ frameNum ]();
			}
		}
		
		
		
	}